package br.com.async.domain.reserve;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import br.com.async.domain.AgileRoomEntity;
import br.com.async.domain.person.Person;
import br.com.async.domain.room.Room;

@Entity(name = "tb_reserve")
public class Reserve implements AgileRoomEntity<Integer> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@SequenceGenerator(initialValue = 1, allocationSize = 1, name = "reserve_seq", sequenceName = "reserve_seq")
	@GeneratedValue(generator = "reserve_seq", strategy = GenerationType.AUTO)
	@Column(nullable = false)
	private Integer code;

	@Temporal(TemporalType.DATE)
	private Calendar date;

	private Boolean active;

	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "room")
	private Room room;

	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "attendant")
	private Person personAttendant;

	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "responsible")
	private Person personResponsible;

	@OneToOne (cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn (name="shift")
	private Shift shift;

	// @Enumerated(EnumType.STRING)
	// private Time time;

	// @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	// @Column(name="time")
	// @org.hibernate.annotations.CollectionOfElements(
	// targetElement = java.lang.String.class
	// )

	@ManyToMany (cascade = CascadeType.ALL, fetch = FetchType.EAGER)
//	@OneToMany (cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private List<Time> times = new ArrayList<Time>();

	public Reserve() {

	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public Calendar getDate() {
		return date;
	}

	public void setDate(Calendar date) {
		this.date = date;
	}

	public Boolean getActive() {
		return active;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	public Room getRoom() {
		return room;
	}

	public void setRoom(Room room) {
		this.room = room;
	}

	public Person getPersonAttendant() {
		return personAttendant;
	}

	public void setPersonAttendant(Person personAttendant) {
		this.personAttendant = personAttendant;
	}

	public Person getPersonResponsible() {
		return personResponsible;
	}

	public void setPersonResponsible(Person personResponsible) {
		this.personResponsible = personResponsible;
	}

	public Shift getShift() {
		return shift;
	}

	public void setShift(Shift shift) {
		this.shift = shift;
	}

	public List<Time> getTimes() {
		return times;
	}

	public void setTimes(List<Time> times) {
		this.times = times;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((active == null) ? 0 : active.hashCode());
		result = prime * result + ((code == null) ? 0 : code.hashCode());
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result
				+ ((personAttendant == null) ? 0 : personAttendant.hashCode());
		result = prime
				* result
				+ ((personResponsible == null) ? 0 : personResponsible
						.hashCode());
		result = prime * result + ((room == null) ? 0 : room.hashCode());
		result = prime * result + ((shift == null) ? 0 : shift.hashCode());
		result = prime * result + ((times == null) ? 0 : times.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Reserve other = (Reserve) obj;
		if (active == null) {
			if (other.active != null)
				return false;
		} else if (!active.equals(other.active))
			return false;
		if (code == null) {
			if (other.code != null)
				return false;
		} else if (!code.equals(other.code))
			return false;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (personAttendant == null) {
			if (other.personAttendant != null)
				return false;
		} else if (!personAttendant.equals(other.personAttendant))
			return false;
		if (personResponsible == null) {
			if (other.personResponsible != null)
				return false;
		} else if (!personResponsible.equals(other.personResponsible))
			return false;
		if (room == null) {
			if (other.room != null)
				return false;
		} else if (!room.equals(other.room))
			return false;
		if (shift == null) {
			if (other.shift != null)
				return false;
		} else if (!shift.equals(other.shift))
			return false;
		if (times == null) {
			if (other.times != null)
				return false;
		} else if (!times.equals(other.times))
			return false;
		return true;
	}

	
	
	
}
